package com.mongodb.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.Point;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhangbowen
 * @date 2019/5/9
 **/
@RestController
@Api(value = "测试")
public class TestController {
    @Autowired
    private MongoTemplate mongoTemplate;

    @PostMapping("test")
    @ApiOperation(value = "测试")
    public List<Test> test(@RequestBody Test test) {
       //  mongoTemplate.save(test);
        Point point = new Point(104.092712402344, 30.7622873783112);
       return mongoTemplate.find(new Query(Criteria.where("geometry").intersects(test.getGeometry())), Test.class);

    }
}
